package com.ruoyi.manage.article.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.manage.article.domain.Contact;
import com.ruoyi.manage.article.service.IContactService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;


import com.ruoyi.common.core.page.TableDataInfo;

/**
 * contactController
 * 
 * @author cc
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/article/contact")
public class ContactController extends BaseController
{
    @Autowired
    private IContactService contactService;

    /**
     * 查询contact列表
     */
    @PreAuthorize("@ss.hasPermi('article:contact:list')")
    @GetMapping("/list")
    public TableDataInfo list(Contact contact)
    {
        startPage();
        List<Contact> list = contactService.selectContactList(contact);
        return getDataTable(list);
    }

    /**
     * 导出contact列表
     */
    @PreAuthorize("@ss.hasPermi('article:contact:export')")
    @Log(title = "contact", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Contact contact)
    {
        List<Contact> list = contactService.selectContactList(contact);
        ExcelUtil<Contact> util = new ExcelUtil<Contact>(Contact.class);
        util.exportExcel(response, list, "contact数据");
    }

    /**
     * 获取contact详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:contact:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(contactService.selectContactById(id));
    }

    /**
     * 新增contact
     */
    @PreAuthorize("@ss.hasPermi('article:contact:add')")
    @Log(title = "contact", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Contact contact)
    {
        return toAjax(contactService.insertContact(contact));
    }

    /**
     * 修改contact
     */
    @PreAuthorize("@ss.hasPermi('article:contact:edit')")
    @Log(title = "contact", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Contact contact)
    {
        return toAjax(contactService.updateContact(contact));
    }

    /**
     * 删除contact
     */
    @PreAuthorize("@ss.hasPermi('article:contact:remove')")
    @Log(title = "contact", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(contactService.deleteContactByIds(ids));
    }
}
